﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Usercontrols
{
    public partial class Default : System.Web.UI.Page
    {
        string tst = "";

        protected void Page_Init(object sender, EventArgs e)
        {
            tst = "init called";
            /*foreach (ControlCollection control in form1.Controls)
            {
                tst += control.ToString()+" ";
            }*/
           tst += uiPersondata.Controls.Count.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            /*Persondata pd = (Persondata)Page.LoadControl("~/Persondata.ascx");
            form1.Controls.Add(pd);*/
            //uiPersondata.FirstName = "Jasper";
            DataTable table = new DataTable();
            table.Columns.Add("Dosage", typeof(int));
            table.Columns.Add("Drug", typeof(string));
            table.Columns.Add("Patient", typeof(string));
            table.Columns.Add("Date", typeof(DateTime));

            table.Rows.Add(25, "Indocin", "David", DateTime.Now);
            table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
            table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
            table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
            table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
            
            

            if (Page.IsPostBack)
            {
                /*TableRow row = new TableRow();
                TableCell cell = new TableCell();
                cell.Controls.Add(new LiteralControl(uiPersondata.FirstName));

                row.Controls.Add(cell);
                uiResultTable.Controls.Add(row);*/
                //table.Rows.Add(20, "Jasper", "Theisen", DateTime.Now);
                table.Rows.Add(20, "Jasper", "Theisen", DateTime.Now);
                SaveUserInput();
            }
            else
            {
                


                form1.Controls.Add(new LiteralControl(tst));


            }                
            uiResultGrid.DataSource = table;
            uiResultGrid.DataBind();
        }
        private void SaveUserInput()
        {
            string firstName = uiPersondata.FirstName.Trim();
            string lastName = uiPersondata.LastName.Trim();
            string address = uiPersondata.Address.Trim();
            string phone = uiPersondata.Phone.Trim();

            string finalString = "|"+firstName+" "+lastName+" "+address+" "+phone;
            //gem bruger input i hidden field
            uiStorage.Value += finalString;
        }
    }
}